package passhashr;
import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;


public class inout {
private int version = 1;
    public boolean isSecurityValid(){
		if((new File("securitycode")).canRead())
			return true;
		return false;
	}
	public void deleteSecurity(){
		(new File("securitycode")).delete();
	}
	
        public void write2file(String code, File f){
		try {
			if(f.createNewFile())
				System.out.println("File Created.");
			else
				System.out.println("File could not be created.");
		} catch (IOException e) {
			e.printStackTrace();
		}
		
	    try {
	      // Create an output stream to the file.
	      FileOutputStream file_output = new FileOutputStream (f);
	      // Wrap the FileOutputStream with a DataOutputStream
	      DataOutputStream data_out = new DataOutputStream (file_output);
	    	  data_out.writeBytes(code);
	      file_output.close();
	    }
	    catch (IOException e) {
	       System.out.println ("I/O exception = " + e );
	    }
	}
        public void DumptoFile(String[] array, File f){
		try {
			if(f.createNewFile())
				System.out.println("File Created.");
			else
				System.out.println("File could not be created.");
		} catch (IOException e) {
			e.printStackTrace();
		}
		
	    try {
	      // Create an output stream to the file.
	      FileOutputStream file_output = new FileOutputStream (f);
	      // Wrap the FileOutputStream with a DataOutputStream
	      DataOutputStream data_out = new DataOutputStream (file_output);
              
	      for (int i=0; i < 97; i++){
	    	  data_out.writeBytes(array[i] + "\n");
	      }
	      file_output.close();
	    }
	    catch (IOException e) {
	       System.out.println ("I/O exception = " + e );
	    }
        }
        
	public void DumptoFile(String[] array, String file){
		File f = new File(file);
		try {
			if(f.createNewFile())
				System.out.println("File Created.");
			else
				System.out.println("File could not be created.");
		} catch (IOException e) {
			e.printStackTrace();
		}
		
	    try {
	      // Create an output stream to the file.
	      FileOutputStream file_output = new FileOutputStream (f);
	      // Wrap the FileOutputStream with a DataOutputStream
	      DataOutputStream data_out = new DataOutputStream (file_output);
              
	      for (int i=0; i < 97; i++){
	    	  data_out.writeBytes(array[i] + "\n");
	      }
	      file_output.close();
	    }
	    catch (IOException e) {
	       System.out.println ("I/O exception = " + e );
	    }
	}
        
	public String[] ReadFile(String file){
		File f = new File(file);
		String[] array = new String[97];

	    try {
	      // Wrap the FileInputStream with a DataInputStream
	      FileInputStream file_input = new FileInputStream (f);
	      BufferedReader data_in  = new BufferedReader(new InputStreamReader(file_input));
	      
              
      	for(int i = 0; i < 97; i++)
        	array[i] = data_in.readLine();
	      data_in.close ();
              
	    }catch(IOException e) {
	       System.out.println ( "IO Exception =: " + e );
	    }
            
	    return array;
            
	}
        public String[] ReadFile(File f){
		String[] array = new String[97];

	    try {
	      // Wrap the FileInputStream with a DataInputStream
	      FileInputStream file_input = new FileInputStream (f);
	      BufferedReader data_in  = new BufferedReader(new InputStreamReader(file_input));
	     
      	for(int i = 0; i < 97; i++)
        	array[i] = data_in.readLine();
	      data_in.close ();
        
	    }catch(IOException e) {
	       System.out.println ( "IO Exception =: " + e );
	    }
	    return array;
	}

        
}
